package view;

import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.Model;

public abstract class ListProvider extends View {
	private List<ListOverlay> listOverlayList;
	private List<Model> modelsToDisplayList;
	private Map<Model, MouseListener> modelToListenerMap;

	/**
	 * The abstract superclass constructor to create an instance of a subclassed ListProvider
	 */
	public ListProvider() {
		setListOverlayList(new ArrayList<ListOverlay>());
		setModelsList(new ArrayList<Model>());
		setListenerMap(new HashMap<Model, MouseListener>());
	}
	
	/**
	 * @param modelsToDisplayList the modelsToDisplayList to set
	 */
	public void setModelsList(List<Model> modelsToDisplayList) {
		this.modelsToDisplayList = modelsToDisplayList;
	}
	/**
	 * @return the modelsToDisplayList
	 */
	public List<Model> getModelsList() {
		return modelsToDisplayList;
	}
	/**
	 * @return the modelToListenerMap
	 */
	public Map<Model, MouseListener> getListenersMap() {
		return modelToListenerMap;
	}
	/**
	 * @param modelToListenerMap the modelToListenerMap to set
	 */
	public void setListenerMap(Map<Model, MouseListener> modelToListenerMap) {
		this.modelToListenerMap = modelToListenerMap;
	}
	/**
	 * Method to use if a ListOverlay would like to subscribe to this list
	 * @param l The ListOverlay to pass in order to be subscribed
	 */
	public void subscribe(ListOverlay l) {
		listOverlayList.add(l);
	}
	/**
	 * Notifies all ListOverlays
	 */
	protected void notifyListOverlays() {
		for(ListOverlay lo : listOverlayList) {
			lo.updateList(this);
		}
	}
	/**
	 * @return the listOverlayList
	 */
	public List<ListOverlay> getListOverlayList() {
		return listOverlayList;
	}
	/**
	 * @param listOverlayList the listOverlayList to set
	 */
	public void setListOverlayList(List<ListOverlay> listOverlayList) {
		this.listOverlayList = listOverlayList;
	}
	/**
	 * Add a model to the internal modelsToDisplayList
	 * @param model the model to add to the internal modelsToDisplayList
	 */
	public void addModelToList(Model model) {
		modelsToDisplayList.add(model);
	}
	/**
	 * Clears the model list
	 */
	public void clearModelToList() {
		modelsToDisplayList.clear();
	}
}
